﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using NextCMS.Models;

/// <summary>
/// Summary description for SiteLanguagesHelper
/// </summary>
public class SiteLanguagesHelper : ISiteLanguage
{
    ISiteLanguage siteLanguages = null;
	public SiteLanguagesHelper()
	{
        siteLanguages = (ISiteLanguage)NextCMS.DataAccess.Entities.CreateInstance<ISiteLanguage>();
	}

    public SiteLanguageModel GetById(int Id)
    {
        return ApplicationCache.SiteLanguages.Where(c=>c.Id==Id).FirstOrDefault();
    }
    public SiteLanguageModel GetByLangCode(string LangCode,int SiteId)
    {
        return ApplicationCache.SiteLanguages.Where(c => c.LangCode.ToLower() == LangCode.ToLower() && c.SiteId == SiteId).FirstOrDefault();
    }
    public SiteLanguageModel GetByLangCode(string LangCode)
    {
        return ApplicationCache.SiteLanguages.Where(c => c.LangCode.ToLower() == LangCode.ToLower()).FirstOrDefault();
    }
    public IEnumerable<SiteLanguageModel> GetAllBySiteId(int SiteId)
    {
        return ApplicationCache.SiteLanguages.Where(c => c.SiteId == SiteId);
    }

    public int Save(SiteLanguageModel page)
    {
        int id= siteLanguages.Save(page);
        ApplicationCache.SiteLanguages = null;
        return id;
    }

    public void Delete(int id)
    {
        siteLanguages.Delete(id);
        ApplicationCache.SiteLanguages = null;
    }

    public void Edit(SiteLanguageModel page)
    {
        siteLanguages.Edit(page);
        ApplicationCache.SiteLanguages = null;
    }

    public void Dispose()
    {
        siteLanguages.Dispose();
        siteLanguages = null;
    }
    
    public  IEnumerable<SiteLanguageModel> GetAll()
    {
        return siteLanguages.GetAll();
    }
}